home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5153 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  58 lines

  1. Path: inforamp.net!ts44-07
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Classes over network?
  5. Date: Fri, 02 Feb 96 19:30:53 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4etoff$7s1@sam.inforamp.net>
  8. References: <4erliv$sva@lastactionhero.rs.itd.umich.edu>
  9. NNTP-Posting-Host: ts44-07.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4erliv$sva@lastactionhero.rs.itd.umich.edu>,
  13.    xxviper@umich.edu (Chris Herringshaw) wrote:
  14. >
  15. >Just wondering if anyone has found a fairly decent way to pass objects
  16. >over network connections.  Nothing extravagent in my objects, like
  17. >other classes, pointers, etc, but I do have one arbitrary length string.
  18. >This suggests that bundling the class up into a struct and using
  19. >RPC would not be very simple.  Any ideas from the guru's?
  20. >
  21. >Thank you.
  22. >
  23.  
  24. You arbitrary length string is it a 
  25.     char *    or a    class string
  26. Use string whenever possible, it helps with class streaming.
  27. I don't know if this helps, but now you could easily write 
  28. the class to a file and send the file.
  29. Example:
  30.  
  31. class MyClass
  32. {
  33. private:
  34.     string lVersion, ui, ui2;
  35. ..
  36. ..
  37.     friend ipstream & operator >> ( ipstream &is, MyClass &p );
  38.     friend opstream & operator << ( opstream &os, const MyClass &p );
  39. };
  40.  
  41. ipstream & operator >> ( ipstream &is, MyClass &p )
  42. {
  43.     is >> p.lVersion
  44.         >> p.ui
  45.         >> p.ui2;
  46.  
  47.   return is;
  48. }
  49.  
  50. opstream & operator << ( opstream &os, const MyClass &p )
  51. {
  52.     os << p.lVersion
  53.         << p.ui
  54.         << p.ui2;
  55.  
  56.     return os;
  57. }
  58.